package OptimalAlgorithm.DivideAndConquer_Quicksort;
//https://leetcode.cn/problems/sort-colors/description/
public class SortColors {
    public void sortColors(int[] nums) {
        int i = 0;
        int left = -1;
        int right = nums.length;
        while (i <= right - 1){
            if(nums[i] == 0){
                swap(i ,left + 1,nums);
                left++;
                i++;
            }else if(nums[i] == 1){
                i++;
            }else {
                swap(right - 1, i ,nums);
                right--;
            }
        }
    }
    public void swap(int i,int j,int[] nums){
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }
}
